package is.billsharing.app;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class RegisterActivity extends Activity
{
	EditText uname,pwd,fname,lname,email,phone,error;
	Button register,regreset;
	
	 @Override
	    public void onCreate(Bundle savedInstanceState) 
	    {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.register);
	        uname=(EditText)findViewById(R.id.reg_uname);
	        pwd=(EditText)findViewById(R.id.reg_pwd);
	        fname=(EditText)findViewById(R.id.reg_fname);
	        lname=(EditText)findViewById(R.id.reg_lname);
	        email=(EditText)findViewById(R.id.reg_email);
	      
	        register=(Button)findViewById(R.id.reg);
           register.setOnClickListener(new View.OnClickListener() 
	        {
	            public void onClick(View v) 
	            {
	                // TODO Auto-generated method stub

	            	ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
	            	postParameters.add(new BasicNameValuePair("username", uname.getText().toString()));
	            	postParameters.add(new BasicNameValuePair("password", pwd.getText().toString()));
	            	postParameters.add(new BasicNameValuePair("firstname", fname.getText().toString()));
	            	postParameters.add(new BasicNameValuePair("lastname", lname.getText().toString()));
	            	postParameters.add(new BasicNameValuePair("emailid", email.getText().toString()));
	            	
	            	String response1;
	             	try {
	             		//response1 = CustomHttpClient.executeHttpPost("http://153.104.91.76/BillsharingServer//BillsharingRegister", postParameters);
	            		response1 = CustomHttpClient.executeHttpPost("BillsharingRegister", postParameters);
	            	    //response1 = CustomHttpClient.executeHttpPost("http://192.168.1.108/BillsharingServer//BillsharingRegister", postParameters);
	            	    String res=response1.toString();
	            	    res= res.replaceAll("\\s+","");
	            	    if(res.equals("true1"))
	            	    {
	            	    	Intent intent=new Intent(RegisterActivity.this,BillsharingappActivity.class);
	            	    	
	            	    	startActivity(intent);
	            	    }
	            	    	else if(res.equals("false1"))
	            	    	{
	            	    		Intent intent=new Intent(RegisterActivity.this,BillsharingappActivity.class);
	                	    	startActivity(intent);
	                	    }
	            	    	else
	            	    	{
	            	    		error.setText(res);
	            	    	}
	            	     
	            	    	
	            	} catch (Exception e) {
	            		
	            		
	            	}
	            	
	            }
	        });
	         
	        
	    }
}
